var create_count=1;
var createResult=1;
function changeImage (box,w) {
    var temp;
    var delay;
    if(w=="create")
    {
        temp=create_count;

    }
    else if(w=="manage") {
        temp=createResult;
    }


    $('#'+box).delay(2000).fadeOut('fast',function() {
   
      
        console.log(temp);


        if(isEven(temp)){ 

   
            $(this).html(_.template( $("#slide_template").html(),{
                "w":w,
                "n":1
            }));
            picturefill();
            $(this).fadeIn();
    
        }
        else
        {
    
            //$(this).css({"background-image":"url(static/images/ss_"+w+"_2.png)"});
            $(this).html(_.template( $("#slide_template").html(),{
                "w":w,
                "n":2
            }));
            picturefill();
            $(this).fadeIn();
        



        }
        if(w=="create")
        {
            create_count++;
            changeImage(box,w);
  
        }
        else if(w=="manage") {
            createResult++;
            changeImage(box,w);
        }
 
 
 
    });
   
   
}

function isEven(value) {
    return (value%2 == 0);
}


function recurseTheShitOut()
{

    $('.at').fadeIn( function(){
        $('#slide').hide().addClass("pass_holder_slide boarding_slide").removeClass('all_slide coupon_slide').fadeIn();
  //      $('.at').html("اشحن كاش");
//        $('.change_text').css({
//            "background-color":"#1889d7"
//        });
    } ).delay(2000);
        
    $('.at').fadeIn(function(){
        $('#slide').hide().addClass("pass_holder_slide event_slide").removeClass('boarding_slide').fadeIn();
//        $('.at').html("event tickets");
//        $('.change_text').css({
//            "background-color":"#e27f38"
//        });
    }).delay(2000);
        
    $('.at').show().fadeIn(function(){
        $('#slide').hide().addClass("store_slide").removeClass('event_slide').fadeIn();
//        $('.at').html("store cards");
//        $('.change_text').css({
//            "background-color":"#00934e"
//        });
    }).delay(2000); 
         
    $('.at').fadeIn(function(){
//        $('.change_text').css({
//            "background-color":"#e8aa05"
//        });
//        $('.at').html("coupons");
        $('#slide').hide().addClass("coupon_slide").removeClass('store_slide').fadeIn(function(){
            recurseTheShitOut();
        });
    }).delay(2000);


}

function earlyaccess(){

    if($('#email').val()!="")
    {
        var email=$('#email').val();
        console.log(email);
        $('.tb_wrap').html('<center><img style="padding-left: 156.5px;padding-right: 156.5px;" src="static/images/wk_loading.gif" width="40"/></center>');
        $.ajax({
            type: 'POST',
            url: "/early",
            data: JSON.stringify({
                "email":email
            }),
            success: function(data){
                var j=jQuery.parseJSON(data);
                console.log(j);
                if(j.success=="true"){
                    $('.tb_wrap').html( _.template( $("#email_done").html()) );
                }

            },
            crossDomain: true,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Content-Type", "application/json");
            }
        });

    }

    else
    {
        $('.tb').css({
            "border-color":"#E90740"
        });
    }

} 